home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Save_Load_2104192292008.psc / version 1.0.1 / frmMain.frm < prev    next >
Text File  |  2008-02-29  |  23KB  |  604 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MsComCtl.ocx"
  3. Begin VB.Form frmDemo 
  4.    Caption         =   "Right Click TreeView or Node To Add/Delete/Change Node Properties"
  5.    ClientHeight    =   6480
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   7950
  9.    Icon            =   "frmMain.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   6480
  12.    ScaleWidth      =   7950
  13.    StartUpPosition =   2  'CenterScreen
  14.    Begin VB.Frame Frame2 
  15.       Caption         =   " TreeView "
  16.       Height          =   1455
  17.       Left            =   3720
  18.       TabIndex        =   16
  19.       Top             =   4920
  20.       Width           =   4095
  21.       Begin VB.CommandButton cmdSaveTree 
  22.          Caption         =   "Save Current TreeView To PropertyBag"
  23.          Height          =   375
  24.          Left            =   120
  25.          TabIndex        =   18
  26.          Top             =   840
  27.          Width           =   3855
  28.       End
  29.       Begin VB.CommandButton cmdLoadTree 
  30.          Caption         =   "Load TreeView From PropertyBag"
  31.          Height          =   375
  32.          Left            =   120
  33.          TabIndex        =   17
  34.          Top             =   360
  35.          Width           =   3855
  36.       End
  37.    End
  38.    Begin MSComctlLib.ImageList demoImgList 
  39.       Left            =   7320
  40.       Top             =   0
  41.       _ExtentX        =   1005
  42.       _ExtentY        =   1005
  43.       BackColor       =   -2147483643
  44.       ImageWidth      =   16
  45.       ImageHeight     =   16
  46.       MaskColor       =   12632256
  47.       _Version        =   393216
  48.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  49.          NumListImages   =   12
  50.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  51.             Picture         =   "frmMain.frx":08CA
  52.             Key             =   "iClosed"
  53.          EndProperty
  54.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  55.             Picture         =   "frmMain.frx":307C
  56.             Key             =   "iOpen"
  57.          EndProperty
  58.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  59.             Picture         =   "frmMain.frx":582E
  60.             Key             =   "iLeaf"
  61.          EndProperty
  62.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  63.             Picture         =   "frmMain.frx":6240
  64.             Key             =   "iBAS"
  65.          EndProperty
  66.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  67.             Picture         =   "frmMain.frx":6B1A
  68.             Key             =   "iCLASS"
  69.          EndProperty
  70.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  71.             Picture         =   "frmMain.frx":73F4
  72.             Key             =   "iShapes"
  73.          EndProperty
  74.          BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  75.             Picture         =   "frmMain.frx":7CCE
  76.             Key             =   "iVB"
  77.          EndProperty
  78.          BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  79.             Picture         =   "frmMain.frx":85A8
  80.             Key             =   "iCube"
  81.          EndProperty
  82.          BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  83.             Picture         =   "frmMain.frx":8E82
  84.             Key             =   "iDiamonds"
  85.          EndProperty
  86.          BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  87.             Picture         =   "frmMain.frx":975C
  88.             Key             =   "iDocPlus"
  89.          EndProperty
  90.          BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  91.             Picture         =   "frmMain.frx":A036
  92.             Key             =   "iText"
  93.          EndProperty
  94.          BeginProperty ListImage12 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  95.             Picture         =   "frmMain.frx":A910
  96.             Key             =   "iSelected"
  97.          EndProperty
  98.       EndProperty
  99.    End
  100.    Begin VB.Frame Frame1 
  101.       Caption         =   " Selected Node Properties "
  102.       Height          =   4695
  103.       Left            =   3720
  104.       TabIndex        =   1
  105.       Top             =   120
  106.       Width           =   4095
  107.       Begin VB.TextBox txtSelectedNodeTag 
  108.          Height          =   285
  109.          Left            =   1800
  110.          TabIndex        =   25
  111.          Text            =   "txtSelectedNodeTag"
  112.          Top             =   2280
  113.          Width           =   2175
  114.       End
  115.       Begin VB.ComboBox cmbNodeChecked 
  116.          Height          =   315
  117.          Left            =   1800
  118.          Style           =   2  'Dropdown List
  119.          TabIndex        =   22
  120.          Top             =   3720
  121.          Width           =   2175
  122.       End
  123.       Begin VB.ComboBox cmbNodeSorted 
  124.          Height          =   315
  125.          Left            =   1800
  126.          Style           =   2  'Dropdown List
  127.          TabIndex        =   20
  128.          Top             =   3360
  129.          Width           =   2175
  130.       End
  131.       Begin VB.TextBox txtSelNodeKey 
  132.          Height          =   285
  133.          Left            =   1800
  134.          TabIndex        =   19
  135.          Text            =   "txtSelNodeKey"
  136.          Top             =   1560
  137.          Width           =   2175
  138.       End
  139.       Begin VB.CommandButton cmdApplyChanges 
  140.          Caption         =   "Apply Changes To Treeview (NOT Saved)"
  141.          Enabled         =   0   'False
  142.          Height          =   375
  143.          Left            =   120
  144.          TabIndex        =   15
  145.          Top             =   4200
  146.          Width           =   3855
  147.       End
  148.       Begin VB.ComboBox cmbSelectedImage 
  149.          Height          =   315
  150.          Left            =   1800
  151.          Style           =   2  'Dropdown List
  152.          TabIndex        =   14
  153.          Top             =   3000
  154.          Width           =   2175
  155.       End
  156.       Begin VB.ComboBox cmbRegImg 
  157.          Height          =   315
  158.          Left            =   1800
  159.          Style           =   2  'Dropdown List
  160.          TabIndex        =   12
  161.          Top             =   2640
  162.          Width           =   2175
  163.       End
  164.       Begin VB.TextBox txtSelectedNodeText 
  165.          Height          =   285
  166.          Left            =   1800
  167.          TabIndex        =   10
  168.          Text            =   "txtSelectedNodeText"
  169.          Top             =   1920
  170.          Width           =   2175
  171.       End
  172.       Begin VB.Label Label10 
  173.          BackStyle       =   0  'Transparent
  174.          Caption         =   "Selected Node Tag:"
  175.          Height          =   195
  176.          Left            =   120
  177.          TabIndex        =   24
  178.          Top             =   2280
  179.          Width           =   1440
  180.       End
  181.       Begin VB.Label Label9 
  182.          BackStyle       =   0  'Transparent
  183.          Caption         =   "Node Checked?"
  184.          Height          =   255
  185.          Left            =   120
  186.          TabIndex        =   23
  187.          Top             =   3720
  188.          Width           =   1335
  189.       End
  190.       Begin VB.Label Label8 
  191.          BackStyle       =   0  'Transparent
  192.          Caption         =   "Node Sorted?"
  193.          Height          =   255
  194.          Left            =   120
  195.          TabIndex        =   21
  196.          Top             =   3360
  197.          Width           =   1575
  198.       End
  199.       Begin VB.Label Label7 
  200.          BackStyle       =   0  'Transparent
  201.          Caption         =   "Selected Image:"
  202.          Height          =   195
  203.          Left            =   120
  204.          TabIndex        =   13
  205.          Top             =   3000
  206.          Width           =   1155
  207.       End
  208.       Begin VB.Label Label6 
  209.          BackStyle       =   0  'Transparent
  210.          Caption         =   "Selected Node Image:"
  211.          Height          =   195
  212.          Left            =   120
  213.          TabIndex        =   11
  214.          Top             =   2640
  215.          Width           =   1590
  216.       End
  217.       Begin VB.Line Line1 
  218.          X1              =   120
  219.          X2              =   3480
  220.          Y1              =   1080
  221.          Y2              =   1080
  222.       End
  223.       Begin VB.Label Label5 
  224.          BackStyle       =   0  'Transparent
  225.          Caption         =   "Selected Node Text"
  226.          Height          =   195
  227.          Left            =   120
  228.          TabIndex        =   9
  229.          Top             =   1920
  230.          Width           =   1425
  231.       End
  232.       Begin VB.Label lblParentNodeKey 
  233.          BackStyle       =   0  'Transparent
  234.          Caption         =   "lblParentNodeKey"
  235.          Height          =   255
  236.          Left            =   1800
  237.          TabIndex        =   8
  238.          Top             =   720
  239.          Width           =   1695
  240.       End
  241.       Begin VB.Label Label4 
  242.          BackStyle       =   0  'Transparent
  243.          Caption         =   "Parent Node Key:"
  244.          Height          =   195
  245.          Left            =   120
  246.          TabIndex        =   7
  247.          Top             =   720
  248.          Width           =   1260
  249.       End
  250.       Begin VB.Label lblParentNodeIndex 
  251.          BackStyle       =   0  'Transparent
  252.          Caption         =   "lblParentNodeIndex"
  253.          Height          =   255
  254.          Left            =   1800
  255.          TabIndex        =   6
  256.          Top             =   360
  257.          Width           =   1695
  258.       End
  259.       Begin VB.Label Label3 
  260.          BackStyle       =   0  'Transparent
  261.          Caption         =   "Parent Node Index:"
  262.          Height          =   195
  263.          Left            =   120
  264.          TabIndex        =   5
  265.          Top             =   360
  266.          Width           =   1380
  267.       End
  268.       Begin VB.Label Label2 
  269.          BackStyle       =   0  'Transparent
  270.          Caption         =   "Selected Node Key:"
  271.          Height          =   195
  272.          Left            =   120
  273.          TabIndex        =   4
  274.          Top             =   1560
  275.          Width           =   1425
  276.       End
  277.       Begin VB.Label lblSelNodeIndex 
  278.          BackStyle       =   0  'Transparent
  279.          Caption         =   "lblSelNodeIndex"
  280.          Height          =   255
  281.          Left            =   1800
  282.          TabIndex        =   3
  283.          Top             =   1200
  284.          Width           =   1695
  285.       End
  286.       Begin VB.Label Label1 
  287.          BackStyle       =   0  'Transparent
  288.          Caption         =   "Selected Node Index:"
  289.          Height          =   195
  290.          Left            =   120
  291.          TabIndex        =   2
  292.          Top             =   1200
  293.          Width           =   1545
  294.       End
  295.    End
  296.    Begin MSComctlLib.TreeView demoTView 
  297.       Height          =   6255
  298.       Left            =   120
  299.       TabIndex        =   0
  300.       Top             =   120
  301.       Width           =   3375
  302.       _ExtentX        =   5953
  303.       _ExtentY        =   11033
  304.       _Version        =   393217
  305.       Style           =   7
  306.       ImageList       =   "demoImgList"
  307.       Appearance      =   1
  308.    End
  309.    Begin VB.Menu mnuPopUp 
  310.       Caption         =   "PopUp"
  311.       Visible         =   0   'False
  312.       Begin VB.Menu mnuAdd2Root 
  313.          Caption         =   "Add Node To Root"
  314.       End
  315.       Begin VB.Menu mnuAddChild 
  316.          Caption         =   "Add Child To Selected Node"
  317.       End
  318.       Begin VB.Menu mnuHyph1 
  319.          Caption         =   "-"
  320.       End
  321.       Begin VB.Menu mnuRemoveNode 
  322.          Caption         =   "Remove Selected Node"
  323.       End
  324.    End
  325. End
  326. Attribute VB_Name = "frmDemo"
  327. Attribute VB_GlobalNameSpace = False
  328. Attribute VB_Creatable = False
  329. Attribute VB_PredeclaredId = True
  330. Attribute VB_Exposed = False
  331. Option Explicit
  332. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  333. '++ TreeView Load/Save using propertybag demo                                            ++
  334. '++ Ver. 1.0.1 Written by: CptnVic  29 Feb. 2008                                         ++
  335. '++ Ver. 1.0.0 Written by: CptnVic  7 Feb. 2008                                          ++
  336. '++ Copyright: Author retains ownership and his rights to use this code, however, you may++
  337. '++            use the code in your projects as you wish with no restriction provided    ++
  338. '++            that you leave this copyright notice intact.                              ++
  339. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  340. '++ The code in this form's module is just to allow you to play around with the treeview ++
  341. '++ and the SaveTree and LoadTree subs in the module.                                    ++
  342. '++ The SaveTree sub doesn't care how you add/modify/delete nodes in the treeview since  ++
  343. '++ it parses the treeview when the SaveTree sub is called.  Therefore, you can use your ++
  344. '++ own methods for adding, etc., nodes to the treeview.                                 ++
  345. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  346. '++ BTW:                                                                                 ++
  347. '++ The form code is not the point of this demo - but if you want to test this project   ++
  348. '++ from scratch, simply delete the demoTView.bag, and demoTView.dat files (included in  ++
  349. '++ the zip file) from the application's directory, run the program and experiment as    ++
  350. '++ you wish.                                                                            ++
  351. '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  352. Private Type CountInfo
  353.     iCnt As Integer 'change to long if you plan to add more than 32,767 items over time
  354. End Type
  355.  
  356. Dim TreeIsDirty As Boolean 'a flag indication changes in the treeview
  357.  
  358. Private Sub cmdApplyChanges_Click()
  359.     '-----------------------------------------------------------
  360.     '-- apply changes made in property frame to selected node --
  361.     '-----------------------------------------------------------
  362.     If demoTView.SelectedItem Is Nothing Then Exit Sub 'see: demoTView_MouseUp for details
  363.     
  364.     Dim NodX As Node
  365.     
  366.     demoTView.SelectedItem.Key = txtSelNodeKey
  367.     demoTView.SelectedItem.Text = txtSelectedNodeText
  368.     demoTView.SelectedItem.Tag = txtSelectedNodeTag
  369.     demoTView.SelectedItem.Image = cmbRegImg.Text
  370.     demoTView.SelectedItem.SelectedImage = cmbSelectedImage.Text
  371.     demoTView.SelectedItem.Sorted = cmbNodeSorted.Text
  372.     demoTView.SelectedItem.Checked = cmbNodeChecked
  373.     TreeIsDirty = True
  374.  
  375. End Sub
  376.  
  377. Private Sub cmdLoadTree_Click()
  378.     'load/reload tree
  379.     LoadTree demoTView 'Load the treeview - use the default filename
  380.     TreeIsDirty = False
  381. End Sub
  382.  
  383. Private Sub cmdSaveTree_Click()
  384.     SaveTree demoTView 'save the treeview - use the default filename - do not back up
  385.     TreeIsDirty = False
  386. End Sub
  387.  
  388. Private Sub demoTView_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  389.     If Button And vbRightButton Then PopupMenu mnuPopUp
  390. End Sub
  391.  
  392. Private Sub demoTView_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  393.     If demoTView.SelectedItem Is Nothing Then
  394.         '-- If you downloaded version 1.0.0 - you would notice that I formerly tested for
  395.         '-- the selected item by generating an error in var = demoTView.SelectedItem.Index
  396.         '-- This was a bad coding practice I used mimicking some MSDN code I saw during my
  397.         '-- research.  Since the demoTView.SelectedItem.Index generated an error if no item
  398.         '-- had been selected, it worked fine... however, the actual error being generated
  399.         '-- was: (91) "Object variable or With block variable not set".  Therefore, the error
  400.         '-- I was using to exit the sub could not exist if no node had been selected - since
  401.         '-- by definition if demoTView.SelectedItem Is Nothing Then demoTView.SelectedItem.Index
  402.         '-- would not make any sense.
  403.         '-- The short version is: testing if demoTView.SelectedItem Is Nothing makes more sense
  404.         '-- and is a better code practice.
  405.         Exit Sub 'don't show properties
  406.     End If
  407.     
  408.     If Button And vbLeftButton Then
  409.         ShowItemProperties
  410.         cmdApplyChanges.Enabled = True
  411.     End If
  412.  
  413. End Sub
  414.  
  415. Private Sub Form_Load()
  416.     
  417.     ClearInfo
  418.     LoadKeys
  419.     LoadTree demoTView 'load the treeview passing the treeview name
  420.     TreeIsDirty = False
  421. End Sub
  422. Private Sub ShowItemProperties()
  423.     '--------------------------------------------------------------------------------------------
  424.     '-- This sub displays the selected node properties as they currently exist in the treeview --
  425.     '--------------------------------------------------------------------------------------------
  426.     If demoTView.SelectedItem Is Nothing Then Exit Sub
  427.     
  428.     lblParentNodeIndex.Caption = GetParent(demoTView.SelectedItem.Index)
  429.     lblParentNodeKey.Caption = GetParentKey(demoTView.SelectedItem.Index)
  430.     lblSelNodeIndex.Caption = demoTView.SelectedItem.Index
  431.     txtSelNodeKey.Text = demoTView.SelectedItem.Key
  432.     txtSelectedNodeText.Text = demoTView.SelectedItem.Text
  433.     txtSelectedNodeTag.Text = demoTView.SelectedItem.Tag
  434.     cmbRegImg.ListIndex = GetIconNum(demoTView.SelectedItem.Image)
  435.     cmbSelectedImage.ListIndex = GetIconNum(demoTView.SelectedItem.SelectedImage)
  436.     cmbNodeSorted.ListIndex = Abs(CInt(demoTView.SelectedItem.Sorted)) 'convert boolean to a useful listindex value
  437.     cmbNodeChecked.ListIndex = Abs(CInt(demoTView.SelectedItem.Checked)) 'ditto
  438.     
  439. End Sub
  440.  
  441. Private Sub ClearInfo()
  442.     '---------------------------------------------------
  443.     '-- This sub just clears the selected node labels --
  444.     '---------------------------------------------------
  445.     lblParentNodeIndex.Caption = ""
  446.     lblParentNodeKey.Caption = ""
  447.     lblSelNodeIndex.Caption = ""
  448.     txtSelNodeKey.Text = ""
  449.     txtSelectedNodeText.Text = ""
  450.     txtSelectedNodeTag.Text = ""
  451.     cmbRegImg.ListIndex = -1
  452.     cmbSelectedImage.ListIndex = -1
  453.     cmbNodeSorted.ListIndex = -1
  454.     cmbNodeChecked.ListIndex = -1
  455. End Sub
  456. Private Sub LoadKeys()
  457.     '-------------------------------------------------------------------
  458.     '-- Load available icons to combo boxes and sorted/checked values --
  459.     '-------------------------------------------------------------------
  460.     Dim i As Integer
  461.     
  462.     cmbRegImg.Clear
  463.     cmbSelectedImage.Clear
  464.     For i = 1 To demoImgList.ListImages.Count
  465.         cmbRegImg.AddItem demoImgList.ListImages(i).Key
  466.         cmbSelectedImage.AddItem demoImgList.ListImages(i).Key
  467.     Next
  468.     cmbNodeSorted.Clear
  469.     cmbNodeSorted.AddItem "False"
  470.     cmbNodeSorted.AddItem "True"
  471.     cmbNodeChecked.Clear
  472.     cmbNodeChecked.AddItem "False"
  473.     cmbNodeChecked.AddItem "True"
  474. End Sub
  475.  
  476. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  477.     '-------------------------------------
  478.     '-- Check treeview file saved state --
  479.     '-------------------------------------
  480.     Dim Response As Integer
  481.     If TreeIsDirty Then
  482.         Response = MsgBox("Do You Want To Save The TreeView Contents Before Exiting?", vbYesNo + vbQuestion, "TreeView Contents Have Not Been Saved!")
  483.         If Response = vbYes Then 'save the treeview before exiting
  484.             SaveTree demoTView, False
  485.         End If
  486.     End If
  487. End Sub
  488.  
  489. Private Sub Form_Unload(Cancel As Integer)
  490.     Set frmDemo = Nothing
  491. End Sub
  492.  
  493. Private Sub mnuAdd2Root_click()
  494.     AddRoot demoTView
  495. End Sub
  496. Private Sub AddRoot(tView As TreeView)
  497.     '-----------------------------------
  498.     '--add a node (no parent) to root --
  499.     '-----------------------------------
  500.     Dim NodX As Node
  501.     Dim tCnt As Integer
  502.     
  503.     tCnt = IncrementCounter(tView)
  504.     Set NodX = tView.Nodes.Add(, , "N" & tCnt, "Untitled(" & tCnt & ")", "iClosed", "iOpen")
  505.     NodX.Checked = False
  506.     NodX.Sorted = False
  507.     TreeIsDirty = True
  508. End Sub
  509.  
  510. Private Sub mnuAddChild_Click()
  511.     'add a child node to the selected node
  512.     AddChild demoTView
  513.     
  514. End Sub
  515. Private Sub AddChild(tView As TreeView)
  516.     '--------------------------------
  517.     '-- Add a child node to parent --
  518.     '--------------------------------
  519.     If demoTView.SelectedItem Is Nothing Then Exit Sub
  520.     
  521.     Dim NodX As Node
  522.     Dim tCnt As Integer, itemNdx As Integer
  523.         
  524.     itemNdx = tView.SelectedItem.Index
  525.     tCnt = IncrementCounter(tView)
  526.     Set NodX = tView.Nodes.Add(itemNdx, tvwChild, "N" & tCnt, "Untitled(" & tCnt & ")", "iClosed", "iOpen")
  527.     NodX.Checked = False
  528.     NodX.Sorted = False
  529.     NodX.EnsureVisible
  530.     TreeIsDirty = True
  531.  
  532. End Sub
  533.  
  534. Private Sub mnuRemoveNode_Click()
  535.     '------------------------------
  536.     '-- Remove the selected Node --
  537.     '------------------------------
  538.     If demoTView.SelectedItem Is Nothing Then Exit Sub
  539.     
  540.     demoTView.Nodes.Remove demoTView.SelectedItem.Index 'Removes the Node and any children it has
  541.     cmdApplyChanges.Enabled = False
  542.     ClearInfo
  543.  
  544. End Sub
  545. Private Function GetIconNum(Str As String) As Integer
  546.     '----------------------------------------
  547.     '-- Returns the list index for an icon --
  548.     '----------------------------------------
  549.     GetIconNum = -1
  550.     Dim x As Integer
  551.     For x = 0 To cmbRegImg.ListCount - 1
  552.         If Str = cmbRegImg.List(x) Then
  553.             GetIconNum = x
  554.         End If
  555.     Next
  556. End Function
  557. Private Function GetParent(iNdx As Integer) As Integer
  558.     '------------------------------------
  559.     '-- Return the parent index if any --
  560.     '------------------------------------
  561.         
  562.     If demoTView.Nodes(iNdx).Parent Is Nothing Then
  563.         GetParent = 0
  564.     Else
  565.         GetParent = demoTView.Nodes(iNdx).Parent.Index
  566.     End If
  567.  
  568. End Function
  569. Private Function GetParentKey(iNdx As Integer) As String
  570.     '----------------------------------------
  571.     '-- Return the parent index key if any --
  572.     '----------------------------------------
  573.     If demoTView.Nodes(iNdx).Parent Is Nothing Then
  574.         GetParentKey = "None"
  575.     Else
  576.         GetParentKey = demoTView.Nodes(iNdx).Parent.Key
  577.     End If
  578.     
  579. End Function
  580. Private Function IncrementCounter(tView As TreeView) As Integer
  581.     '-------------------------------------------------------
  582.     '-- Return the next index # for serializing node keys --
  583.     '-------------------------------------------------------
  584.     Dim cFile As String
  585.     Dim ctr As CountInfo
  586.     Dim F As Integer
  587.     
  588.     'create/read a counter file to prevent clashes in item keys
  589.     cFile = getdir & tView.Name & ".dat" 'name is based on treeview.name to allow for multiple treeviews
  590.     F = FreeFile
  591.     Open cFile For Random As #F Len = Len(ctr) 'Random access will not generate an error if the file does not exist... it will just create the file
  592.         If LOF(F) = 0 Then
  593.             ctr.iCnt = 0
  594.             Put #F, 1, ctr
  595.         End If
  596.         Get #F, 1, ctr
  597.         IncrementCounter = ctr.iCnt + 1
  598.         ctr.iCnt = IncrementCounter
  599.         Put #F, 1, ctr
  600.     Close #F
  601. End Function
  602.  
  603.  
  604.